package com.gua.jbs.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.gua.jbs.daoImpl.BaseDao;
import com.gua.jbs.daoImpl.IAllProductDao;
import com.gua.jbs.pojo.Jbspit;
import com.gua.jbs.utility.ApplicationException;
import com.gua.jbs.utility.DBConstant;
import com.gua.jbs.utility.ExceptionMessage;
import com.gua.jbs.utility.QueryConstant;

public class AllProductDao extends BaseDao implements IAllProductDao {

	/**
	 * Method to get all products of system
	 */
	public List<Jbspit> getAllProductDao()throws ApplicationException {
		
		List<Jbspit> list_allProd = new ArrayList<Jbspit>();
		String query = QueryConstant.ALL_PRODUCT;

		try {
			ResultSet rs = getResults(query);
			// System.out.println("PROD_NAME"+rs.getString("PROD_NAME"));
			while (rs.next()) {

				Jbspit objPit = new Jbspit();
				objPit.setProdId(String.valueOf(rs.getInt("ID")));
				objPit.setProdName(rs.getString("PROD_NAME"));
				objPit.setProdColor(rs.getString("COLOR"));
				objPit.setProdSize(String.valueOf(rs.getBigDecimal("SIZE")));
				objPit.setProdCode(rs.getString("BAR_CODE"));
				objPit.setProdType(rs.getString("TYPE"));
				objPit.setProdSubType(rs.getString("SUB_TYPE"));
				objPit.setProdImage(rs.getString("IMAGE"));
				objPit.setExtrafield2((rs.getString("POLISH")));
				objPit.setProdPrice((rs.getString("PRICE")));
				objPit.setProdCost((rs.getString("COST")));
				objPit.setHrCode((rs.getString("HR_CODE")));
				objPit.setDesignCode((rs.getString("DESIGN_CODE")));
				objPit.setExtrafield1(rs.getString("DESCRIPTION"));
				objPit.setExtrafield3(rs.getString("STOCK"));
				objPit.setIsApproved(rs.getString("APPROVAL"));
				objPit.setCreateDate(rs.getDate("CREATED_DT"));
				list_allProd.add(objPit);
			}
			return list_allProd;

		} catch (SQLException sqe) {
			throw new ApplicationException(
					ExceptionMessage.PRODUCT_LIST_UNABLE_TO_FETCH);
		}

	}

}
